import aiohttp
from config import ZHUQUE_COOKIE,ZHUQUE_CSRF

# 请求头信息
headers = {
    "method": "GET",
    "authority": "zhuque.in",
    "scheme": "https",
    "sec-ch-ua": '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
    "accept": "application/json, text/plain, */*",
    "content-type": "application/json",
    "x-csrf-token": ZHUQUE_CSRF,
    "sec-ch-ua-mobile": "?0",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
    "sec-ch-ua-platform": '"Windows"',
    "origin": "https://zhuque.in",
    "sec-fetch-site": "same-origin",
    "sec-fetch-mode": "cors",
    "sec-fetch-dest": "empty",
    "referer": "https://zhuque.in/gaming/genshin/character/list",
    "accept-language": "zh-CN,zh;q=0.9",
    "cookie": ZHUQUE_COOKIE,
}
listGenshinCharacter_url = "https://zhuque.in/api/gaming/listGenshinCharacter"


def deal_genshin_character_list_data(listGenshinCharacter):
    rank_total_genshin = {4: 483014, 5: 1022028}
    cost, total, magic = 0, 0, 0
    for character in listGenshinCharacter["data"]["characters"]:
        cost += character["info"]["cost"]
        total += rank_total_genshin[character["rank"]]
        if character["magic"] == 1:
            fire_gen = 100 + character["info"]["level"] * 60
            fire_gen *= 1 if character["rank"] == 4 else 2
            match character["info"]["profit"] / character["info"]["cost"]:
                case x if x > 1.5:
                    fire_gen *= 0.5
                case x if x > 2.5:
                    fire_gen *= 0.25
                case x if x > 3.5:
                    fire_gen *= 0.1
            magic += fire_gen
    return cost, total, magic


async def get_list():
    async with aiohttp.ClientSession() as session:
        async with session.get(listGenshinCharacter_url, headers=headers) as response:
            if response.status == 200:
                return await response.json()
